//搜索二维矩阵
class Solution {
public:
    bool searchMatrix(vector<vector<int>>& matrix, int target) {
        int n = matrix.size();
        int left = 0;
        int right = n - 1;
        while (left < right) {
            int mid = left + (right - left + 1) / 2;
            if (matrix[mid][0] <= target)
                left = mid;
            else
                right = mid - 1;
        }
        int m = matrix[0].size();
        int x = left;
        left = 0;
        right = m - 1;
        //   int mid = left + (right - left) / 2;

        while (left <= right) {
            int mid = left + (right - left) / 2;
            if (matrix[x][mid] < target)
                left = mid + 1;
            else if (matrix[x][mid] > target)
                right = mid - 1;
            else
                return true;
        }
        // if (matrix[x][left])
        return false;
    }
};